package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.ScoreItem;
import com.wuseguang.springcloud.entity.TeacherClassEvaluationItems;
import com.wuseguang.springcloud.service.ScoreItemService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 评分项表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-02-02
 */
@RestController
@RequestMapping("/scoreItem")
public class ScoreItemController {

    @Autowired
    private ScoreItemService scoreItemServiceImpl;

    private Logger logger  = LoggerFactory.getLogger(this.getClass());

    /**
     * 查询教师的评分项
     * @param request
     * @return
     */
    @RequestMapping("/findScoreItem")
    public Result findScoreItem(RequestParameterWrapper request){

        logger.info("查询教师的评分项");
        //教师id
        String teacherId = request.getParam("teacherId");
        return scoreItemServiceImpl.findScoreItem(teacherId);
    }

    /**
     * 添加教师的评分项
     * @param request
     * @param scoreItem 评分项
     * @return
     */
    @RequestMapping("/addScoreItem")
    public Result addScoreItem(RequestParameterWrapper request, ScoreItem scoreItem){

        logger.info("添加教师的评分项");

        //教师id
        String teacherId = request.getParam("teacherId");
        //学校id
        String schoolId = request.getParam("schoolId");
        scoreItem.setTeacherId(Integer.valueOf(schoolId));
        return scoreItemServiceImpl.addScoreItem(scoreItem,teacherId);
    }

    /**
     * 删除评分项
     * @param request
     * @param id 评分项id
     * @return
     */
    @RequestMapping("/deleteScoreItem")
    public Result deleteScoreItem(RequestParameterWrapper request, @RequestParam(value = "id")Integer id){
        logger.info("删除评分项");

        return scoreItemServiceImpl.deleteScoreItem(id);
    }

    /**
     * 修改评分项
     * @param request
     * @param scoreItem 评分项信息
     * @return
     */
    @RequestMapping("/updateScoreItem")
    public Result updateScoreItem(RequestParameterWrapper request, @RequestBody ScoreItem scoreItem){
        logger.info("修改评分项");
        return scoreItemServiceImpl.updateScoreItem(scoreItem);
    }

    /**
     * 导入班级评价项
     * @param request
     * @param classId 班级id
     * @param scoreItemId 评价项id
     * @return
     */
    @RequestMapping("/importClassEvaluationItems")
    public Result importClassEvaluationItems(RequestParameterWrapper request,
                                             @RequestParam(value = "classId")Integer classId,
                                             @RequestParam(value = "scoreItemId")Integer [] scoreItemId,
                                             @RequestParam(value = "type") Integer type){
        //教师id
        String teacherId = request.getParam("teacherId");
        logger.info("导入班级评价项");
        return scoreItemServiceImpl.importClassEvaluationItems(classId,scoreItemId,teacherId,type);
    }

    /**
     * 根据类型查询这个老师在这个班级的评价项状态
     * @param request
     * @param classId 班级id
     * @param type 0表扬,1待改进
     * @return
     */
    @RequestMapping("/findScoreItemType")
    public Result findScoreItemType(RequestParameterWrapper request,
                                    @RequestParam(value = "classId")Integer classId,
                                    @RequestParam(value = "type",defaultValue = "0")Integer type){
        //教师id
        String teacherId = request.getParam("teacherId");
        logger.info("根据类型查询这个老师在这个班级的评价项状态");
        return scoreItemServiceImpl.findScoreItemType(classId,type,teacherId);
    }

    /**
     * 查询这个老师在这个班的评分项
     * @param request
     * @param classId 班级id
     * @return
     */
    @RequestMapping("/findTecherClassScoreItem")
    public Result findTecherClassScoreItem(RequestParameterWrapper request,
                                           @RequestParam(value = "classId")Integer classId ){
        //教师id
        String teacherId = request.getParam("teacherId");
        logger.info("查询这个老师在这个班的评分项");
        return scoreItemServiceImpl.findTecherClassScoreItem(classId,teacherId);
    }

    /**
     * 刪除教師在這個班的评价項
     * @param request
     * @param id
     * @return
     */
    @RequestMapping("/delteTecherClassScoreItem")
    public Result delteTecherClassScoreItem(RequestParameterWrapper request,
                                            @RequestParam(value = "id")Integer id ){
        logger.info("刪除教師在這個班的评价項");
        return scoreItemServiceImpl.delteTecherClassScoreItem(id);
    }
}

